home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / AIIe / TN.AIIE.006 < prev    next >
Encoding:
Text File  |  1989-04-22  |  17.4 KB  |  323 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIe
  8. #6:    The Apple II Paddle Circuits
  9.  
  10. Revised by:    Glenn A. Baxter                                  November 1988
  11. Written by:    Peter Baum                                            May 1984
  12.  
  13. This Technical Note describes the paddle circuit used in the Apple II family 
  14. of computers.
  15. _____________________________________________________________________________
  16.  
  17.  
  18. Caveats
  19.  
  20. Since Apple has introduced machines with internal clock speeds which may not 
  21. be exactly 1.023 MHz, it is best to use the PREAD firmware call to read paddle 
  22. data.  This Note assumes that the clock speed of the system is exactly 1.023 
  23. MHz.  If you want to insure accuracy in reading paddle data, you should make 
  24. sure the system is first running at the correct speed.  Enough information is 
  25. provided so that you can write your own PREAD routine, although this is 
  26. discouraged.  If the program runs on an Apple IIGS or some future machine, 
  27. your custom paddle reading routine will fail to give the correct results.
  28.  
  29.  
  30. Circuit Description
  31.  
  32. The value of the Apple paddles (or joystick) is determined by a software 
  33. timing loop reading a change of state in a timing circuit.  The paddles 
  34. consist of a variable resistor (from 0-150k ohms) which makes up part of the 
  35. timing circuit.  There is a routine in the monitor ROM, called PREAD, which 
  36. counts the time until a state change occurs in the paddle circuit.  This time 
  37. is translated into a value between 0 and 255.
  38.  
  39. The block diagrams in Figures 1 and 2 show the paddle circuit for the Apple 
  40. ][+, Apple IIc, and the Apple IIe.  The large block on the left illustrates 
  41. part of the circuitry inside the 558 timer chip.  The 558 chip consists of 
  42. four of these blocks, with all four paddle triggers lines shorted together on 
  43. the motherboard and activated by the soft switch at $C070.  The outputs of the 
  44. 558 chip run into a multiplexer, which places the appropriate signal onto the 
  45. high bit of the data bus when a paddle soft switch address in the range $C064 
  46. $C067 is read.  The Apple IIc uses a 556 timer rather than the 558 chip and 
  47. only supports two paddles, 0 and 1.
  48.  
  49. The 100 ohm resistor and .022 microfarad capacitor are on the motherboard, 
  50. with the variable resistor in the paddle.  Each of the four paddle inputs have 
  51. their own capacitor and resistor.  Since these components can vary by as much 
  52. as five percent from Apple to Apple, this circuit is not a very exact analog 
  53. to digital converter.  If a paddle is moved from one Apple to another without 
  54. changing the resistance (turning the knob), the paddle read routine will 
  55. probably calculate a different value for each machine.  About the only feature 
  56. of the paddle read routine that a programmer can depend on is that the value 
  57. returned will rise if the paddle resistance increases (or fall if the 
  58. resistance decreases).
  59.  
  60. The paddle timing circuit on the Apple ][+ and Apple IIc is slightly different 
  61. than the one on the Apple IIe.  On the Apple IIe, the 100 ohm fixed resistor 
  62. is between the transistor and the capacitor, while the variable resistor in 
  63. the paddle is connected directly to the capacitor.  On the Apple ][+ and IIc, 
  64. the capacitor is connected directly to the transistor and the fixed resistor 
  65. is in series with paddle resistor.
  66.  
  67.  _______________________________________________
  68. |                   556 Timer                   |
  69. |    ^ VCC                                      |               _____________
  70. |    |                                          |              |             |
  71. |    \                                          |              |   Paddle    |
  72. |    /                                          |              |      ^      |
  73. | 5K \                                          |              |      |  ^   |
  74. |    /    +-----------------------------------------O---+      |      \ /    |
  75. |    \    |                                     |       |      |      //     |
  76. |    |    |            ___________              |       |      |      X      |
  77. |    +------- + |\    |           |             |       |      |     //      |
  78. |    |    |     | >---|RESET      |             |       |      |    / \      |
  79. |    \    +-- - |/    |           |             |       |      |______|______|
  80. |    /                |           |             |       |             |
  81. | 5K \  Comparator    |           |             |       |    100 ohm  |
  82. |    /                | FLIP FLOP |         +-------O---+--+-\/\/\/\--+
  83. |    \                |           |         |   |          |
  84. |    |                |           |        /    |          |
  85. |    +------- + |\    |          _|      |/     |         _|_
  86. |    |          | >---|SET       Q|---+--|\     |         ___ .022uF
  87. |    \    +-- - |/    |___________|   |  | \>   |          |
  88. |    /    |                           |     |   |          |
  89. | 5K \    |                           |     +---|---O------+
  90. |    /    |                           |   __|__ |
  91. |    \    |                           |    ---  |
  92. |  __|__  |                           |     -   |
  93. |   ---   |                           |  |\     |
  94. |    -    |                           +--| >O---|---O Output
  95. |         |                              |/     |     ($C06x)
  96. |_________|_____________________________________|
  97.           |
  98.           O Trigger
  99.             ($C070)
  100.  
  101.                     Figure 1 - Apple ][+ and IIc Paddle Circuit
  102.  
  103.  
  104. An Example of a Typical Paddle Read Routine
  105.  
  106. The timing circuit works by discharging a capacitor through a transistor, then 
  107. shutting the transistor off and letting the paddle charge the capacitor by 
  108. supplying current through the variable resistor.  The rate at which the 
  109. capacitor charges is a function of the variable resistance; the lower the 
  110. paddle resistance, the greater the current and the faster the capacitor 
  111. charges.  When the capacitor reaches a predetermined value it changes the 
  112. state of a flip flop. The paddle read routine counts the time it takes for the 
  113. capacitor to rise and change the flip flop.
  114.  
  115. Let's step through an example of a typical paddle read operation.  For now we 
  116. will assume the capacitor has already been discharged and in a few pages I 
  117. will explain when this assumption can be made and when it cannot.
  118.  
  119. The software starts by reading the soft switch at location $C070, which 
  120. strobes the trigger lines on the 558 timer.  This action causes two events to 
  121. occur, the output signal (which is read at $C064-$C067 for paddle 0-3, 
  122. respectively) goes high and the transistor turns off.
  123.  
  124. The software, after initially strobing the trigger line, executes a timing 
  125. loop which reads the state of the output signal.  When the output signal 
  126. changes from high to low the software jumps out of the timing loop and returns 
  127. a value indicating the time.  The monitor PREAD routine consists of a 11 µsec. 
  128. loop and will return a value between 0 and 255.  (Note:  The firmware listing 
  129. is wrong and says the loop is 12 µsec.)  The timing loop returns 255 if the 
  130. circuit takes longer than 2.82 ms for the state change to occur.
  131.  
  132.  _______________________________________________
  133. |                   558 Timer                   |
  134. |    ^ VCC                                      |               _____________
  135. |    |                                          |              |             |
  136. |    \                                          |              |   Paddle    |
  137. |    /                                          |              |      ^      |
  138. | 5K \                                          |              |      |  ^   |
  139. |    /    +---------------------------------+   |              |      \ /    |
  140. |    \    |                                 |   |              |      //     |
  141. |    |    |            ___________          |   |              |      X      |
  142. |    +------- + |\    |           |         |   |              |     //      |
  143. |    |    |     | >---|RESET      |         |   |              |    / \      |
  144. |    \    +-- - |/    |           |         |   |              |______|______|
  145. |    /                |           |         |   |                     |
  146. | 5K \  Comparator    |           |         |   |      100 ohm        |
  147. |    /                | FLIP FLOP |         +-------O--\/\/\/\--+-----+
  148. |    \                |           |         |   |               |
  149. |    |                |           |        /    |               |
  150. |    +------- + |\    |          _|      |/     |              _|_
  151. |    |          | >---|SET       Q|---+--|\     |              ___ .022uF
  152. |    \    +-- - |/    |___________|   |  | \>   |               |
  153. |    /    |                           |     |   |               |
  154. | 5K \    |                           |     +---|---O-----------+
  155. |    /    |                           |   __|__ |
  156. |    \    |                           |    ---  |
  157. |  __|__  |                           |     -   |
  158. |   ---   |                           |  |\     |
  159. |    -    |                           +--| >O---|---O Output
  160. |         |                              |/     |     ($C06x)
  161. |_________|_____________________________________|
  162.           |
  163.           O Trigger
  164.             ($C070)
  165.  
  166.                       Figure 2 - Apple IIe Paddle Circuit
  167.  
  168.  
  169. * PADDLE READ ROUTINE
  170. * ENTER WITH PADDLE NUMBER (0-3) IN X-REG
  171.  
  172. FB1E:AD 70 C0  PREAD   4  LDA  PTRIG     ;TRIGGER PADDLES
  173. FB21:A0 00             2  LDY  #0        ;INIT COUNTER
  174. FB23:EA                2  NOP            ;COMPENSATE FOR 1ST COUNT
  175. FB24:EA                2  NOP
  176. FB25:BD 64 C0  PREAD2  4  LDA  PADDL0,X  ;COUNT EVERY 11 µSEC.
  177. FB28:10 04             2  BPL  RTS2D     ;BRANCH WHEN TIMED OUT
  178. FB2A:C8                2  INY            ;INCREMENT COUNTER
  179. FB2B:D0 F8             3  BNE  PREAD2    ;CONTINUE COUNTING
  180. FB2D:88                   DEY            ;COUNTER OVERFLOWED
  181. FB2E:60        RTS2D      RTS            ;RETURN W/VALUE 0-255
  182.  
  183. Inside the 558 timer chip, when the trigger is strobed low, the comparator 
  184. that feeds the set input of the flip flop is triggered, which in turn sets the 
  185. output of the 558 timer.  At the same time, the transistor, which has held the 
  186. capacitor near ground by sinking current from it, is shut off.  The capacitor 
  187. can now charge using the current supplied by the paddle.  The smaller the 
  188. paddle's resistance, the more current the paddle will supply and the faster 
  189. the capacitor charges.  After some time, the capacitor will charge to the 
  190. threshold value of 3.3 volts, which is set by the voltage divider network in 
  191. the 558 timer, and the comparator that feeds the reset input on the flip flop 
  192. will trigger.  This trigger sets the output signal ($C06x) of the 558 timer 
  193. low, which indicates to the software that the circuit has timed out.
  194.  
  195.               _____        ___________________________________________________
  196. Trigger $C070      |      |
  197.                    |______|
  198.  
  199.                              _______________________________ 
  200.                            _|                               |<------ Threshold
  201. Feedback to              _|                                 |_
  202. Reset Comp _____________|                                     |_______________
  203.  
  204.                          ___________________________________
  205.                         |                                   |
  206. Output _________________|                                   |_________________
  207.                                     Timing Value
  208.                         |<--------------------------------->|
  209.                                 0 - 2.82 milliseconds
  210.  
  211.                       Figure 3 - Paddle Circuit Recharge Timing
  212.  
  213. Resetting the flip flop turns the transistor on, which discharges the 
  214. capacitor very quickly (normally less than 250 ns).  That paddle can then be 
  215. read again.
  216.  
  217.  
  218. A Closer Look at the Hardware
  219.  
  220. The First Anomaly
  221.  
  222. Notice that the last sentence states that the paddle can be read again and not 
  223. the paddles.  If another paddle is read immediately after the first, it may 
  224. yield the wrong value.  To demonstrate this, I will step through an example of 
  225. reading a second paddle immediately after finishing the first.
  226.  
  227. In this example I will assume that the first paddle has been set with a very 
  228. low resistance, while the second paddle has a high resistance.  The first 
  229. paddle will time out very quickly and return with a small value, while the 
  230. second paddle will take longer and yield a larger value.
  231.  
  232. We start reading the paddles by testing the paddle outputs to see if they are 
  233. low, which indicates that the capacitor has been discharged.  Assuming that 
  234. the outputs are low, the next step is to trigger the 558 timer ($C070), which 
  235. turns off the transistor and allows the capacitors to charge.  Since all of 
  236. the trigger input lines are shorted together, all four of the capacitors will 
  237. charge, but at different rates since the paddle resistances have been set to 
  238. different values.  The voltage on the capacitor for the first paddle will 
  239. reach the threshold voltage very quickly since the paddle resistance has been 
  240. set low, therefore the timing loop will time out quickly.
  241.  
  242. At this point the capacitor for the second paddle is still charging and has 
  243. not yet reached the threshold since the paddle resistance was set to a high 
  244. value.  The transistor for the second paddle is still turned off due to the 
  245. initial trigger used for reading paddle one.  This means that the capacitor 
  246. for the second paddle has not been discharged.
  247.  
  248. Any attempts at reading the second paddle now will only yield false results.  
  249. The capacitor is partly charged and therefore will reach the threshold value 
  250. much faster than if the capacitor had been completely discharged.  If the 
  251. timing loop is used, it will return with a smaller value than it would if the 
  252. capacitor had been completely discharged.  Notice that retriggering (reading 
  253. location $C070) the 558 timer will not help, since that only keeps the 
  254. transistor turned off and does not help discharge the capacitor.  The only way 
  255. for the capacitor to discharge is to let the circuit time out completely by 
  256. letting the capacitor charge until it resets the flip flop.
  257.  
  258. To read the second paddle, the capacitor must first be discharged, which is 
  259. only done when the threshold value is reached and the 558 timer flip flop is 
  260. reset.  The only way to guarantee that the capacitor is discharged is if the 
  261. transistor is on.  This condition is met when the paddle output is low.  
  262. Therefore, start every paddle read either by waiting for at least 3 ms before 
  263. strobing the trigger input or testing to make sure that the paddle output is 
  264. low.
  265.  
  266. If after 4 ms the paddle output is not low, then there is a good chance that 
  267. there is no paddle connected.  This result may also indicate that a peripheral 
  268. with a larger maximum value resistor than the 150k ohms used by the Apple 
  269. paddles is attached. Some peripheral devices use this technique of a larger 
  270. variable resistor so that more than 256 points of resolution can be 
  271. determined.  Of course, this requires a custom software driver and the monitor 
  272. PREAD routine cannot be used.
  273.  
  274. Apple IIe Anomalies
  275.  
  276. The problem with Apple IIe paddle input is that the capacitor may not be 
  277. discharged by the transistor.  Typically, the transistor will discharge the 
  278. capacitor in less than 250 ns on the Apple ][+.  But on the Apple IIe, if the 
  279. paddle resistance is very low then the paddle may supply enough current to 
  280. always keep the capacitor charged.
  281.  
  282. Because the fixed resistor (100 ohms) on the Apple IIe motherboard is between 
  283. the capacitor and the transistor, there will be a voltage drop across the 
  284. resistor if the capacitor stays charged.  When the transistor is shut off by 
  285. the trigger strobe, this voltage drop will disappear and the capacitor, which 
  286. may be near the threshold voltage, will trigger the reset comparator earlier 
  287. than it would if the capacitor had been discharged completely.  The net affect 
  288. of this is that the paddles will read zero on the Apple IIe when they would 
  289. read a small value on the Apple ][+ or IIc.
  290.  
  291. Other circuits which expect the capacitor to discharge completely may not work 
  292. properly.  A circuit which attempts to simulate a paddle through active 
  293. components such as a digital to analog converter may be able to source enough 
  294. current that the capacitor never discharges and the paddle always reads zero.
  295.  
  296. It should also be noted that due to electromagnetic interference, later model 
  297. IIe computers actually have an extra capacitor attached between the BUTTON 
  298. inputs and ground.  This essentially slows the response time of the input, 
  299. making a fully digital input appear a bit more analog (no pun intended).  Care 
  300. should be taken in designing system which depend on a certain repetition rate 
  301. of the button inputs.  Careful engineering and testing across systems should 
  302. prevent any problems.  As an example, adding a transistor output stage to 
  303. drive the button inputs to the appropriate states might be a good idea for a 
  304. serializing A/D.  A joystick would not require this kind of circuit because 
  305. the user input is too slow to be affected by the capacitors.  For more 
  306. information on the changes in later model IIe computers, refer to Apple IIe 
  307. Technical Note #9, Switch Input Changes.
  308.  
  309.  
  310. Conclusion
  311.  
  312. Hopefully, this Note has given the reader a good feel for the paddle circuitry 
  313. and the routines which determine the paddle values.  To reinforce the material 
  314. covered, you should try writing your own paddle read routine.  For example, 
  315. you could write a read routine that would read two paddles at once.  The 
  316. software loop will not have the 11 µsec. resolution of the PREAD routine, but 
  317. you will find it still works just fine.  Happy programming.
  318.  
  319.  
  320. Further Reference
  321.     o    Apple IIe Technical Reference Manual
  322.  
  323.